var planID = getQueryString("planID");

$(function () {
    $("#jqGrid").Grid({
        url: '../modulemaintainrelate/list?planID=' + planID,
        colModel: [
            {label: '序号', name: 'moduleMaintainOption.orNum', width: 60},
            {label: '一级名称', name: 'moduleMaintainOption.optionSubclass', width: 80},
            {label: '二级名称', name: 'moduleMaintainOption.optionName', width: 80},
            {label: '方法手段', name: 'moduleMaintainOption.method', index: 'METHOD', width: 80},
            {label: '检查标准', name: 'moduleMaintainOption.inspectStandard', index: 'INSPECT_STANDARD', width: 120},
            {label: '选项备注', name: 'moduleMaintainOption.optionRemark', index: 'OPTION_REMARK', width: 80},
            {label: '记录', name: 'moduleMaintainOption.rocords', index: 'ROCORDS', width: 80},
            {label: 'id', name: 'id', index: 'ID', key: true, hidden: true}
        ]
    });
});

var vm = new Vue({
    el: '#rrapp',
    data: {
        showList: true,
        title: null,
        q: {
            name: ''
        }
    },
    methods: {
        query: function () {
            vm.reload();
        },
        del: function (event) {
            // 获取待删除内容
            var ids = getSelectedRows("#jqGrid");
            if(!ids){
                iview.Message.error("请选择备件记录");
                return;
            }
            Ajax.request({
                url: "../modulemaintainrelate/delete",
                params: JSON.stringify(ids),
                type: "POST",
                contentType: "application/json",
                successCallback: function (r) {
                    alert(r.msg, function (index) {
                        vm.reload();
                        layer.closeAll();
                    });
                }
            });
        },
        reload: function (event) {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                postData: {'name': vm.q.name},
                page: page
            }).trigger("reloadGrid");
        },
        reloadSearch: function () {
            vm.q = {
                name: ''
            };
            vm.reload();
        },
        handleSubmit: function (name) {
            handleSubmitValidate(this, name, function () {
                vm.saveOrUpdate()
            });
        },
        saves:function(){
            Ajax.request({
                url: "../modulemaintainplan/save" ,
                params: JSON.stringify(vm.moduleMaintainPlan),
                type: "POST",
                contentType: "application/json",
                successCallback: function (r) {
                    alert('操作成功', function (index) {
                        vm.reload();
                        layer.closeAll();
                    });
                }
            });
        }
    }
});